home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / managers / mc-3.2 / mc-3 / mc-3.2.1 / src / dlg.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  9.3 KB  |  292 lines

  1. #ifndef MC_DLG_H
  2. #define MC_DLG_H
  3. #include "mouse.h"
  4. #include "util.h"
  5.  
  6. /* Color constants */
  7. #define FOCUSC           h->color[1]
  8. #define NORMALC          h->color[0]
  9. #define HOT_NORMALC      h->color[2]
  10. #define HOT_FOCUSC       h->color[3]
  11.  
  12. /* Possible directions */
  13. #define DIR_FORWARD     1
  14. #define DIR_BACKWARD    0
  15.  
  16. /* Common return values */
  17. #define B_EXIT        0
  18. #define B_CANCEL    1
  19. #define B_ENTER        2
  20. #define B_HELP        3
  21. #define B_USER          100
  22.  
  23. /* Widget messages */
  24. enum {
  25.     WIDGET_INIT,        /* Initialize widget */
  26.     WIDGET_FOCUS,        /* Draw widget in focused state */
  27.     WIDGET_UNFOCUS,        /* Draw widget in unfocused state */
  28.     WIDGET_DRAW,        /* Sent to widget to draw themselves */
  29.     WIDGET_KEY,            /* Sent to widgets on key press */
  30.     WIDGET_HOTKEY,        /* Sent to widget to catch preprocess key */
  31.     WIDGET_DESTROY,        /* Sent to widget at destruction time */
  32.     WIDGET_CURSOR,        /* Sent to widget to position the cursor */
  33.     WIDGET_IDLE,        /* Send to widgets with options & W_WANT_IDLE*/
  34.     WIDGET_USER  = 0x100000
  35.  
  36. } /* Widget_Messages */;
  37.  
  38. enum {
  39.     MSG_NOT_HANDLED,
  40.     MSG_HANDLED
  41. } /* WRET */;
  42.  
  43. /* Widgets are expected to answer to the following messages:
  44.  
  45.    WIDGET_FOCUS:   1 if the accept the focus, 0 if they do not.
  46.    WIDGET_UNFOCUS: 1 if they accept to release the focus, 0 if they don't.
  47.    WIDGET_KEY:     1 if they actually used the key, 0 if not.
  48.    WIDGET_HOTKEY:  1 if they actually used the key, 0 if not.
  49. */
  50.  
  51. /* Dialog messages */
  52. enum {
  53.     DLG_KEY,            /* Sent on keypress before sending to widget */
  54.     DLG_INIT,            /* Sent on init */
  55.     DLG_END,            /* Sent on shutdown */
  56.     DLG_ACTION,            
  57.     DLG_DRAW,            /* Sent for updating dialog managed area */
  58.     DLG_FOCUS,            /* Sent on give focus to a widget */
  59.     DLG_UNFOCUS,        /* Sent on remove focus from widget */
  60.     DLG_ONE_UP,            /* Sent on selecting next */
  61.     DLG_ONE_DOWN,        /* Sent on selecting prev */
  62.     DLG_POST_KEY,        /* Sent after key has been sent */
  63.     DLG_IDLE,            /* Sent if idle is active */
  64.     DLG_UNHANDLED_KEY,        /* Send if no widget wanted the key */
  65.     DLG_HOTKEY_HANDLED,        /* Send if a child got the hotkey */
  66.     DLG_PRE_EVENT               /* Send before calling get_event */
  67. } /* Dialog_Messages */;
  68.  
  69. typedef unsigned long widget_data;
  70. typedef struct Dlg_head {
  71.     int *color;            /* color set */
  72.     int count;            /* number of widgets */
  73.     int ret_value;
  74.  
  75.     /* mouse status */
  76.     int mouse_status;        /* For the autorepeat status of the mouse */
  77.  
  78.     void *previous_dialog;    /* Pointer to the previously running Dlg_head */
  79.     int  refresh_pushed;    /* Did the dialog actually run? */
  80.     
  81.     /* position */
  82.     int x, y;            /* Position relative to screen origin */
  83.     
  84.     /* Flags */
  85.     int running;
  86.     int direction;
  87.     int send_idle_msg;
  88.  
  89.     char *name;            /* Dialog name Tk code */
  90.     char *help_ctx;
  91.  
  92.     /* Internal variables */
  93.     struct Widget_Item *current, *first, *last;
  94.     int (*callback) (struct Dlg_head *, int, int);
  95.     
  96.     struct Widget_Item *initfocus;
  97.  
  98.     /* Hacks */
  99.     char *title;
  100.  
  101.     int cols;
  102.     int lines;
  103.     void *data;
  104.     
  105.     int  has_menubar;    /* GrossHack: Send events on row 1 to a menubar? */
  106.     int  raw;        /* Should the tab key be sent to the dialog? */
  107.     
  108.     widget_data wdata;
  109.     
  110. } Dlg_head;
  111.  
  112. /* XView widget layout */
  113.  
  114. typedef enum { 
  115.     XV_WLAY_DONTCARE, /* Place the widget wherever it is reasonable */
  116.     
  117.     XV_WLAY_RIGHTOF,  /* Place the widget to the right of the last widget
  118.                * created - note: add_widget creates widgets from
  119.                *  the last to the first one.
  120.                */
  121.     
  122.     XV_WLAY_BELOWOF,  /* Place it in a column like style */
  123.     
  124.     XV_WLAY_BELOWCLOSE,/* The same, but without any gap between them */
  125.     
  126.     XV_WLAY_NEXTROW,  /* Place it on the left margin with Y bellow all the
  127.                * previous widgets
  128.                */
  129.     
  130.     XV_WLAY_CENTERROW,/* The same as previous, but when the dialog is
  131.                * ready to show, tries to center that row of widgets
  132.                */
  133.     
  134.     XV_WLAY_NEXTCOLUMN, /* Place it on the top margin with X behind all the
  135.                * previous widgets
  136.                */
  137.                
  138.     XV_WLAY_RIGHTDOWN, /* Place the widget to the right of the last one with
  139.                     * y set so that both y + h and yold + hold are equal.
  140.                       This is usefull if the previous widget was a radio,
  141.                       which has multiple lines */
  142.     XV_WLAY_EXTENDWIDTH  /* Like nextrow, but later on tries to extend the widget
  143.                           * to fit in the frame (only for PANEL_LIST) */
  144. } WLay;
  145.  
  146. /* Every Widget must have this as it's first element */
  147. typedef struct Widget {
  148.     int x, y;
  149.     int cols, lines;
  150.     int color;            /* If the widget uses it, the color */
  151.     int options;
  152.     int focused;        /* Tells if the widget is focused */
  153.     int (*callback)(Dlg_head *, void *, int, int);  /* The callback function */
  154.     void (*destroy)(void *);
  155.     mouse_h mouse;
  156.     struct Dlg_head *parent;
  157.     widget_data wdata;
  158.     widget_data wcontainer;   /* For children of midnight_dlg, identifies
  159.                                * the frame in which they should reside
  160.                    */
  161.     char *frame;        /* Tk version: frame containing it */
  162.     enum {
  163.         AREA_TOP,
  164.         AREA_LEFT,
  165.         AREA_RIGHT,
  166.         AREA_BOTTOM
  167.     } area; /* Used by X platforms, should stay here always because the size
  168.                of this structure has to be same everywhere :) */
  169.     WLay  layout;
  170. } Widget;
  171.  
  172. /* The options for the widgets */
  173. #define  W_WANT_POST_KEY     1
  174. #define  W_WANT_HOTKEY       2
  175. #define  W_WANT_CURSOR       4
  176. #define  W_WANT_IDLE         8
  177.  
  178. typedef struct Widget_Item {
  179.     int dlg_id;
  180.     struct Widget_Item *next;    /* next in circle buffer */
  181.     struct Widget_Item *prev;    /* previous in circle buffer */
  182.     Widget *widget;        /* point to the component */
  183. } Widget_Item;
  184.  
  185. /* draw box in window */
  186. void draw_box (Dlg_head *h, int y, int x, int ys, int xs);
  187. /* doubled line if possible */
  188. void draw_double_box (Dlg_head *h, int y, int x, int ys, int xs);
  189.  
  190. /* Creates a dialog head  */
  191. Dlg_head *create_dlg (int y1, int x1, int lines, int cols,
  192.               int *col,
  193.               int (*callback) (struct Dlg_head *, int, int),
  194.               char *help_ctx, char *name, int flags);
  195.  
  196. /* The flags: */
  197. #define DLG_TRYUP       2    /* Try to move two lines up the dialog */
  198. #define DLG_CENTER      1    /* Center the dialog */
  199. #define DLG_NONE        0    /* No options */
  200.  
  201. int  add_widget (Dlg_head *dest, void *Widget);
  202. int  add_widgetl (Dlg_head *dest, void *Widget, WLay layout);
  203.  
  204. /* Runs dialog d */
  205. void run_dlg (Dlg_head *d);
  206.  
  207. void dlg_run_done (Dlg_head *h);
  208. void dlg_process_event (Dlg_head *h, int key, Gpm_Event *event);
  209. void init_dlg (Dlg_head *h);
  210.  
  211. /* To activate/deactivate the idle message generation */
  212. void set_idle_proc (Dlg_head *d, int state);
  213.  
  214. void dlg_redraw (Dlg_head *h);
  215. void dlg_refresh (void *parameter);
  216. void destroy_dlg (Dlg_head *h);
  217. void widget_set_size (Widget *widget, int x1, int y1, int x2, int y2);
  218. void dlg_broadcast_msg_to (Dlg_head *h, int message, int reverse, int flags);
  219. void dlg_broadcast_msg (Dlg_head *h, int message, int reverse);
  220. void dlg_mouse (Dlg_head *h, Gpm_Event *event);
  221. int default_dlg_callback (Dlg_head *h, int id, int msg);
  222.  
  223. typedef void  (*destroy_fn)(void *);
  224. typedef int   (*callback_fn)(Dlg_head *, void *, int, int);
  225.  
  226. void init_widget (Widget *w, int y, int x, int lines, int cols,
  227.           callback_fn callback, destroy_fn destroy,
  228.           mouse_h mouse_handler);
  229. int std_callback (Dlg_head *h, int Msg, int Par);
  230. int default_proc (Dlg_head *h, int Msg, int Par);
  231.  
  232. /* Nay, it has to be elsewhere, this header if widely used
  233. #ifdef HAVE_X
  234. #  ifndef move
  235. #      define move(a,b)
  236. #  endif
  237. #endif
  238.  */
  239.  
  240. #define real_widget_move(w, _y, _x) move((w)->y + _y, (w)->x + _x)
  241. #define dlg_move(h, _y, _x) move(((Dlg_head *) h)->y + _y, \
  242.                  ((Dlg_head *) h)->x + _x)
  243.  
  244. #define widget_move(w,y,x) real_widget_move((Widget*)w,y,x)
  245.  
  246.  
  247. extern Dlg_head *current_dlg;
  248. extern Hook *idle_hook;
  249.  
  250. int send_message (Dlg_head *h, Widget *w, int msg, int par);
  251. int send_message_to (Dlg_head *h, Widget *w, int msg, int par);
  252. void dlg_replace_widget (Dlg_head *h, Widget *old, Widget *new);
  253. void widget_redraw (Dlg_head *h, Widget_Item *w);
  254. int dlg_overlap (Widget *a, Widget *b);
  255. void widget_erase (Widget *);
  256. void dlg_erase (Dlg_head *h);
  257.  
  258. /* Widget selection */
  259. int  dlg_select_widget (struct Dlg_head *h, void *widget);
  260. void dlg_one_up (Dlg_head *h);
  261. void dlg_one_down (Dlg_head *h);
  262. int  dlg_focus (Dlg_head *h);
  263. int  dlg_unfocus (Dlg_head *h);
  264. int dlg_select_nth_widget (Dlg_head *h, int n);
  265. int dlg_item_number (Dlg_head *h);
  266. Widget *find_widget_type (Dlg_head *h, callback_fn signature);
  267.  
  268. /* Sets/clear the specified flag in the options field */
  269. #define widget_option(w,f,i) \
  270.     w.options = ((i) ? (w.options | (f)) : (w.options & (~(f))))
  271.  
  272. #define widget_want_cursor(w,i) widget_option(w, W_WANT_CURSOR, i)
  273. #define widget_want_hotkey(w,i) widget_option(w, W_WANT_HOTKEY, i)
  274. #define widget_want_postkey(w,i) widget_option(w, W_WANT_POSTKEY, i)
  275.  
  276. typedef void (*movefn)(void *, int);
  277.  
  278. /* Layout definitions */
  279.  
  280. void xv_Layout (void *first_widget, ...);
  281. void tk_layout (void *first_widget, ...);
  282. void tk_new_frame (Dlg_head *, char *);
  283. void tk_frame (Dlg_head *, char *);
  284. void tk_end_frame ();
  285. void x_set_dialog_title (Dlg_head *h, char *title);
  286.  
  287. /* The inner workings of run_dlg, exported for the Tk and XView toolkits */
  288. void dlg_key_event (Dlg_head *h, int d_key);
  289. void update_cursor (Dlg_head *h);
  290.  
  291. #endif /* MC_DLG_H */
  292.